//
//  mluLawyerCasesEdit.m
//  mluLawyer
//
//  Created by GecanMobile01 on 23/11/09.
//  Copyright 2009 MobileLifeUtils.com. All rights reserved.
//

#import "mluLawyerCasesEdit.h"


@implementation mluLawyerCasesEdit

@synthesize aLabels, aFields, tfCurrent, tvCurrent;

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super initWithStyle:style]) {
    }
    return self;
}
*/

- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super initWithStyle:style]) {
    }
    return self;
}

- (void)viewDidLoad {
	self.title = NSLocalizedString(@"titCases", nil);
    
	UILabel *lblDescription = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 10.0, 280.0, 20.0)];
	[lblDescription setText:NSLocalizedString(@"lblDescription", nil)];
	
	UITextView *tvDescription = [[UITextView alloc] initWithFrame:CGRectMake(13.0, 35.0, 294.0, 130)];
	tvDescription.delegate = self;
	tvDescription.contentInset = UIEdgeInsetsMake(0, 0, 0, -70);
	[tvDescription setBackgroundColor:[UIColor clearColor]];
	
	UILabel *lblNumber = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 10.0, 280.0, 20.0)];
	[lblNumber setText:NSLocalizedString(@"lblNumber", nil)];
	
	UITextField *tfNumber = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 35.0, 280.0, 30.0)];
	tfNumber.delegate = self;
	[tfNumber setBorderStyle:UITextBorderStyleLine];
	
	aLabels = [[NSMutableArray alloc] initWithObjects:lblDescription, lblNumber, nil];
	aFields = [[NSMutableArray alloc] initWithObjects:tvDescription, tfNumber, nil];
}

/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
}

#pragma mark -
#pragma mark UITableViewDelegate methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [aLabels count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	
	switch (indexPath.row) {
		case 0:;
			UITextView *tvDescription = [aFields objectAtIndex:indexPath.row];
			
			UIGraphicsBeginImageContext(tvDescription.frame.size);
			CGContextRef cgcImage = UIGraphicsGetCurrentContext();
			CGContextSetLineWidth(cgcImage, 1.2);
			CGContextSetRGBStrokeColor(cgcImage, 0.0, 0.0, 0.0, 1.0); 
			CGContextStrokeRect(cgcImage, CGRectMake(5, 0, tvDescription.frame.size.width - 15, tvDescription.frame.size.height)); 
			UIImage *imBorder = (UIImage *)UIGraphicsGetImageFromCurrentImageContext();
			UIGraphicsEndImageContext();
			UIImageView *ivBgDescription = [[UIImageView alloc] initWithFrame:tvDescription.frame];
			[ivBgDescription setUserInteractionEnabled:NO];
			ivBgDescription.image = imBorder;
			[cell addSubview:ivBgDescription];
			break;
		default:
			break;
	}
	
	[cell addSubview:[aLabels objectAtIndex:indexPath.row]];
	[cell addSubview:[aFields objectAtIndex:indexPath.row]];
	
	[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
	// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
	// [self.navigationController pushViewController:anotherViewController];
	// [anotherViewController release];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	CGFloat fTableViewRowHeight;
	if (indexPath.row == 0) {
		fTableViewRowHeight = 180.0;
	} else {
		fTableViewRowHeight = 80.0;
	}
	return fTableViewRowHeight;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark -
#pragma mark UIScrollViewDelegate methods

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
	[self endEditing];
}

#pragma mark -
#pragma mark UITextFieldDelegate methods

- (void)textFieldDidBeginEditing:(UITextField *)textField {
	tvCurrent = nil;
	tfCurrent = textField;
}

#pragma mark -
#pragma mark UITextViewDelegate methods

- (void)textViewDidBeginEditing:(UITextView *)textView {
	tfCurrent = nil;
	tvCurrent = textView;
}

#pragma mark -
#pragma mark Custom methods

- (void)endEditing {
	if (tfCurrent != nil || tvCurrent != nil) {
		if (tfCurrent != nil){
			[tfCurrent resignFirstResponder];
		} else {
			[tvCurrent resignFirstResponder];
		}
	}
}

@end

